package com.zhenwei.zscm.controller;

import com.zhenwei.zscm.common.annotations.Insert;
import com.zhenwei.zscm.common.annotations.MethodName;
import com.zhenwei.zscm.common.annotations.Update;
import com.zhenwei.zscm.common.base.RestResult;
import com.zhenwei.zscm.model.vo.productPart.ProductPartVO;
import com.zhenwei.zscm.service.ProductPartService;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/productPart")
@AllArgsConstructor
@MethodName("产品配件管理")
public class ProductPartController {
    private ProductPartService productPartService;

    @MethodName("获取产品配件列表")
    @GetMapping("/list")
    public RestResult getList(@RequestParam @NotEmpty(message = "产品不能为空") String productCode){
        return productPartService.getList(productCode);
    }

    @MethodName("添加产品配件信息")
    @PostMapping("/create")
    public RestResult create(@RequestBody @Validated(Insert.class) ProductPartVO vo) {
        return productPartService.create(vo);
    }

    @MethodName("修改产品配件信息")
    @PostMapping("/update")
    public RestResult update(@RequestBody @Validated(Update.class) ProductPartVO vo) {
        return productPartService.update(vo);
    }

    @MethodName("删除产品配件信息")
    @GetMapping("/delete")
    public RestResult delete(@RequestParam @NotEmpty(message = "主键ID不能为空") String guid) {
        return productPartService.delete(guid);
    }
}
